package org.agilelang.editor.dialog;

/*
 AgileLang - A fourth generation language(http://www.agilelang.org).

 Copyright (C) 2013 Roderick Cusirramos (roderick20@hotmail.com)

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.awt.GridLayout;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import static org.agilelang.editor.tool.I18n._;

public class DlgConfig extends javax.swing.JDialog {

    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnAccept;
    private javax.swing.JButton btnCancel;
    private javax.swing.JComboBox cmbGenerators;
    private javax.swing.JLabel lblPath;
    private javax.swing.JLabel lblGenerators;
    private javax.swing.JTextField txtPath;
    private boolean generate = false;

    public boolean isGenerate() {
        return generate;
    }

    public String getTxtPath() {
        return txtPath.getText();
    }
    
    public String getGenenator() {
        return (String)cmbGenerators.getSelectedItem();
    }

    public DlgConfig(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.setTitle(_("dialog_generate_title"));
        initComponents();
    }

    private void initComponents() {

        btnSearch = new javax.swing.JButton("...");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchActionPerformed(evt);
            }
        });
        btnAccept = new javax.swing.JButton(_("dialog_generate_acept"));
        btnAccept.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AcceptActionPerformed(evt);
            }
        });
        btnCancel = new javax.swing.JButton(_("dialog_generate_cancel"));
        btnCancel.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelActionPerformed(evt);
            }
        });
        cmbGenerators = new javax.swing.JComboBox();
        cmbGenerators.addItem(_("dialog_generate_titlecakephp"));
        cmbGenerators.addItem(_("dialog_generate_titlejavastruts2"));

        
        lblGenerators = new javax.swing.JLabel();
        lblGenerators.setText(_("dialog_generate_generators"));

        lblPath = new javax.swing.JLabel();
        lblPath.setText(_("dialog_generate_path"));
        txtPath = new javax.swing.JTextField(25);

        JPanel pnlSearch = new JPanel();
        JPanel pnlOption = new JPanel();
        JPanel pnlCommand = new JPanel();
        JPanel pnl = new JPanel(new GridLayout(3, 2));

        pnlSearch.add(lblPath);
        pnlSearch.add(txtPath);
        pnlSearch.add(btnSearch);

        pnlOption.add(lblGenerators);
        pnlOption.add(cmbGenerators);

        pnlCommand.add(btnAccept);
        pnlCommand.add(btnCancel);

        pnl.add(pnlSearch);
        pnl.add(pnlOption);
        pnl.add(pnlCommand);

        add(pnl);
        pack();
    }

    private void SearchActionPerformed(java.awt.event.ActionEvent evt) {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int result = fileChooser.showSaveDialog(this);
        if (result == JFileChooser.CANCEL_OPTION) {
            return;
        }
        txtPath.setText(fileChooser.getSelectedFile().getAbsolutePath());

    }

    private void AcceptActionPerformed(java.awt.event.ActionEvent evt) {
        generate = true;
        setVisible(false);
    }

    private void CancelActionPerformed(java.awt.event.ActionEvent evt) {
        generate = false;
        setVisible(false);
    }
}
